import random
from cmath import pi

import pygame


def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600), 0, 32)

    points = []

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
            elif event.type == pygame.KEYDOWN:
                points = []
                screen.fill((255, 255, 255))
            elif event.type == pygame.MOUSEBUTTONDOWN:
                screen.fill((255, 255, 255))
                # 矩形
                rc = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
                rp = (random.randint(0, 799), random.randint(0, 599))
                rs = ((799 - random.randint(rp[0], 799)), (599 - random.randint(rp[1], 599)))
                pygame.draw.rect(screen, rc, pygame.Rect(rp, rs))

                # 圆形
                rc = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
                rp = (random.randint(0, 799), random.randint(0, 599))
                rr = random.randint(1, 200)
                pygame.draw.circle(screen, rc, rp, rr)

                #
                x, y = pygame.mouse.get_pos()
                points.append((x, y))

                # 画弧线
                angle = (x / 799) * pi * 2
                pygame.draw.arc(screen, (0, 0, 0), (0, 0, 799, 599), 0, angle,
                                3)  # Surface, color, Rect, start_angle, stop_angle, width=1

                # 根据点击位置画椭圆
                pygame.draw.ellipse(screen, (0, 255, 0), (0, 0, x, y))

                # 画线
                pygame.draw.line(screen, (0, 0, 255), (0, 0), (x, y))
                pygame.draw.line(screen, (255, 0, 0), (0, 799), (x, y))

                if len(points) > 1:
                    pygame.draw.lines(screen, (127, 127, 127), False, points, 2)

                for p in points:
                    pygame.draw.circle(screen, (155, 155, 155), p, 3)

        pygame.display.update()


main()
